package org.example.sword2offer.primary;

import java.util.Stack;

/**
 * @author: lynn
 * @Descript:两个栈实现队列
 * Question 6
 * @date: 2021/3/8 19:42
 * @version: 1.0
 */
public class Q6_TwoStackForQueue {
    private static Stack<Integer>  stackA=new Stack<>();
    private static Stack<Integer> stackB=new Stack<>();
    public static void main(String[] args) {

        push(1);
        push(3);
        push(5);
        push(8);
        push(9);
        System.out.println(pop());
        System.out.println(pop());
        System.out.println(pop());
        System.out.println(pop());
        System.out.println(pop());
        System.out.println(pop());

    }

    public static void push(int node) {
        stackA.push(node);
    }

    public static int pop() {
        if (stackB.size()!=0){
            while (stackA.size()!=0){
                stackB.push(stackA.pop());
            }
            return stackB.pop();
        }else {
            throw new IllegalArgumentException("no more element！");
        }
    }
}
